<template>
  <div class="change-class body-bg">
    <div v-if="!initLoading">
      <ul class="change-content" v-if="list.length">
        <li class="change-items" v-for="(item,index) in list" :key="index">
          <div class="top border-bottom">
            <div class="head-name">
              <img class="head-img" :src="item.src" alt="头像">
              <p class="name">{{item.childName}}</p>
            </div>
            <div class="class-infor">
              <p class="class-name overflow-tow">{{item.title}}</p>
              <div class="class-bottom">
                <p><img src="/static/images/changeClass/icon1.png" alt="icon">{{item.teacherName}}</p>
                <p><img src="/static/images/changeClass/icon2.png" alt="icon">{{item.shidaoNum}}/{{item.totalNum}}</p>
              </div>
              <div class="class-bottom">
                <p style="width:100%"><img src="/static/images/changeClass/icon4.png" alt="icon"><span class="overflow-one">{{item.address}}</span></p>
              </div>
            </div>
          </div>
          <div class="bottom">
            <span class="bottom-btn" @click="goBuKe">我要补课</span>
          </div>
        </li>
        <li v-if="isReachBottom" class="pull-loading"><van-loading type="spinner" size="20px" color="#1989fa" /></li>
        <li v-if="isBottom" class="bottom-line">-- 亲，已经到最后了--</li>
      </ul>
      <div v-else class="empty">
        <img src="/static/images/empty-icon.png" alt="空">
        <p class="empty-tips">暂时还没有可补课级哦</p>
      </div>
    </div>
    <div v-else class="init-loading"><van-loading type="spinner" color="#1989fa" /></div>
  </div>
</template>

<script>
import store from '../../store/globalStore'
export default {
  data() {
    return {
      initLoading: true, // 初始加载
      isBottom: false, // 是否加载完全部数据
      isReachBottom: false, // 是否显示加载状态
      list: [
        {state: 1, src: 'https://img.yzcdn.cn/vant/cat.jpeg', childName: '孩子姓名', title: '课程名称课程名称课程课程课课程名称课程名称课程课程课课程名称课程名称课程课程课', teacherName: '教练名称', shidaoNum: '17', totalNum: '50', dateTime:'2019年12月12日', address: '北京海淀黄庄校区北京海淀黄庄校区'}
        ,{state: 0, src: 'https://img.yzcdn.cn/vant/cat.jpeg', childName: '孩子姓名', title: '课程名称课程名称课程课程课课程名称课程名称课程课程课课程名称课程名称课程课程课', teacherName: '教练名称', shidaoNum: '17', totalNum: '50', dateTime:'2019年12月12日', address: '北京海淀黄庄校区北京海淀黄庄校区'}
      ]
    }
  },
  onShow() {
    this.getShiftWorkList();
  },
  methods: {
    // 获取列表
    getShiftWorkList() {
      this.$fetch.shiftWork()
      .then(res=>{
        this.initLoading = false;
      }).catch(err=>{
        this.initLoading = false;
      })
    },
    // 去补课
    goBuKe() {
      wx.navigateTo({
        url: '/pages/remedialTeaching/main'
      })
    }
  },
  // 下拉刷新
  onPullDownRefresh: function() {
    console.log("下拉刷新");
    wx.showNavigationBarLoading() //在标题栏中显示加载
    //模拟加载
    setTimeout(function(){
      wx.hideNavigationBarLoading() //完成停止加载
      wx.stopPullDownRefresh() //停止下拉刷新
    },1500);
  },
  // 上拉加载
  onReachBottom () {
    let that = this;
    that.isReachBottom = true;
    wx.showNavigationBarLoading() //在标题栏中显示加载
    if(that.list.length<10){
      setTimeout(function(){
        that.isReachBottom = false;
        wx.hideNavigationBarLoading() //完成停止加载
        //模拟加载
        that.list = [...that.list,...that.list]
      },1500);
    } else {
      that.isReachBottom = false;
      that.isBottom = true;
      wx.hideNavigationBarLoading() //完成停止加载
    }
  },
}
</script>

<style lang="less" scope>
.change-class{
  width: 100%;
  min-height: 100vh;
  .change-content{
    width: 100%;
    .change-items{
      width: 100%;
      background: #fff;
      padding: 16px 18px 0 22px;
      box-sizing: border-box;
      position: relative;
      overflow: hidden;
      margin-bottom: 10px;
      &:last-child{
        border-bottom: 0;
      }
      .top{
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding-bottom: 30px;
      }
      .bottom{
        width: 100%;
        padding: 8px 0;
        box-sizing: border-box;
        display: flex;
        flex-direction: row-reverse;
        .bottom-btn{
          padding: 8px 18px;
          border: 0.5px solid rgba(75,179,253,1);
          border-radius:  14px;
          font-size: 14px;
          color: #4BB3FD;
          background: #fff;
        }
      }
      .head-name{
        width: 110px;
        margin-top: 1px;
        .head-img{
          min-width: 55px;
          width: 55px;
          height: 55px;
          border-radius: 100%;
          display: block;
        }
        .name{
          width: 100%;
          font-size: 14px;
          color: #666;
          font-weight: bold;
          text-align: center;
          margin-top: 15px;
        }
      }
      .zhuanban-state{
        width: 50px;
        height: 16px;
        display: flex;
        align-items: center;
        text-indent: 6px;
        font-size: 10px;
        color: #fff;
        position: absolute;
        top: 0;
        left: 0;
        overflow: hidden;
        &::after{
          content: "";
          width: 20px;
          height: 20px;
          background: #fff;
          position: absolute;
          top: 5px;
          right: -10px;
          transform: rotate(45deg);
        }
      }
      .class-infor{
        flex-grow: 1;
        margin-left: 26px;
        .class-top{
          display: flex;
          width: 100%;
          font-size: 14px;
          font-weight: bold;
        }
        .change-btn{
          display: flex;
          justify-content: center;
          align-items: center;
          min-width: 54px;
          height: 20px;
          text-align: center;
          font-size: 14px;
          color: #fff;
          margin-left: 12px;
          background: #00B7EE;
          border-radius: 10px;
        }
        .class-bottom{
          width: 100%;
          display: flex;
          margin-top: 6px;
          p{
            display: flex;
            align-items: center;
            width: 50%;
            font-size: 12px;
            color: #666;
            overflow: hidden;
            img{
              width: 16px;
              min-width: 16px;
              height: 16px;
              display: block;
              margin-right: 10px;
            }
          }
        }
      }
    }
  }
}
</style>
